package com.daxin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daxin.mapper.GroupMapper;
import com.daxin.pojo.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service("groupService")
public class GroupServiceImpl implements GroupService{
    @Autowired
    private GroupMapper groupMapper;

    @Override
    @Transactional
    public void newGroup(List<String> list) {
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0,9);
        for(String dxid:list){
            Group group = new Group().setDxId(dxid).setGroupId(uuid);
            groupMapper.insert(group);
        }
    }

    @Override
    @Transactional
    public List<Group> findGroup(String dxid) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dx_id", dxid);
        queryWrapper.select("dx_id","group_id");
        List<Group> groupList = groupMapper.selectList(queryWrapper);
        return groupList;
    }
}
